﻿package mortal.game.manager.msgTip
{
    import com.gengine.core.frame.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.font.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;

    public class MsgCopyTaskEndImpl extends Object
    {
        private var _wordTxt:TextField;
        private var _str:String;
        private var _daily:int;
        private var _count:int;
        private var _currentCount:int;
        private var _callBack:Function;
        private var _timer:SecTimer;

        public function MsgCopyTaskEndImpl()
        {
            return;
        }// end function

        private function stopTimer() : void
        {
            if (this._timer && this._timer.running)
            {
                this._timer.stop();
            }
            return;
        }// end function

        private function startTimer() : void
        {
            if (!this._timer)
            {
                this._timer = new SecTimer(this._daily, this._count * this._daily);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                this._timer.addListener(TimerType.COMPLETE, this.onTimerComHandler);
            }
            else
            {
                this._timer.delay = this._daily;
                this._timer.repeatCount = this._count * this._daily;
            }
            if (!this._timer.running)
            {
                this._timer.start();
            }
            return;
        }// end function

        private function onTimerHandler(param1:SecTimer) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this._currentCount - 1;
            _loc_2._currentCount = _loc_3;
            this.setText();
            return;
        }// end function

        private function onTimerComHandler(param1:SecTimer) : void
        {
            if (this._callBack != null)
            {
                this._callBack();
            }
            this.hide();
            return;
        }// end function

        private function setText() : void
        {
            var _loc_1:* = this._str.split("n");
            var _loc_2:String = "#66FF33";
            if (this._currentCount >= this._count * 2 / 3)
            {
                _loc_2 = "#66FF33";
            }
            else if (this._currentCount <= this._count / 3)
            {
                _loc_2 = "#FF0000";
            }
            else
            {
                _loc_2 = "#E46C0A";
            }
            this._wordTxt.htmlText = HTMLUtil.addColor(_loc_1[0] + HTMLUtil.addColor(this._currentCount.toString(), _loc_2) + _loc_1[1], "#ffc000");
            return;
        }// end function

        public function show(param1:String, param2:int, param3:int, param4:Function = null) : void
        {
            this._str = param1;
            this._daily = param2;
            this._count = param3;
            this._currentCount = param3;
            this._callBack = param4;
            this.stopTimer();
            if (!this._wordTxt)
            {
                this._wordTxt = new TextField();
                this._wordTxt.autoSize = TextFieldAutoSize.CENTER;
                this._wordTxt.defaultTextFormat = new GTextFormat(FontUtil.xingkaiName, 24, 16711680, true, null, null, null, TextFormatAlign.CENTER);
                this._wordTxt.filters = [FilterConst.nameGlowFilter];
                this._wordTxt.selectable = false;
                this._wordTxt.mouseEnabled = false;
                this._wordTxt.width = 1000;
                this._wordTxt.height = 100;
            }
            if (this._wordTxt.parent == null)
            {
                LayerManager.windowLayer.addChild(this._wordTxt);
            }
            this.setText();
            this.stageResize();
            this.startTimer();
            return;
        }// end function

        public function hide() : void
        {
            if (this._wordTxt && this._wordTxt.parent != null)
            {
                LayerManager.windowLayer.removeChild(this._wordTxt);
            }
            this.stopTimer();
            return;
        }// end function

        public function stageResize() : void
        {
            if (this._wordTxt && this._wordTxt.parent)
            {
                this._wordTxt.x = (Global.stage.stageWidth - this._wordTxt.textWidth) / 2;
                this._wordTxt.y = Global.stage.stageHeight / 2 - (Global.stage.stageHeight / 2 - this._wordTxt.textHeight) / 2;
            }
            return;
        }// end function

    }
}
